/* 用户资料 */
import router from '@/router'
import { getLoginInfo, clearLoginInfo } from '@/utils/storage.js'
import store from '@/store/index'

export const userIsLogin = (flag) => {
  if (flag) return flag
  // console.log('getLoginInfo', getLoginInfo())
  const info = getLoginInfo()
  return info && info.accessToken
}

export const getStorageUserId = () => {
  const info = getLoginInfo()
  return info && info.userid
}

export const toSignInPage = () => {
  clearLoginInfo()
  /* fixed: 退出登录再次登录进入首页，遗留上次对话记录 */
  store.commit('index/SET_chatList', [])
  router.replace('/signIn')
}

export const hasPermission = (role) => {
  const roles = getLoginInfo()?.roles || []
  return roles.includes(role)
}